Package edu.claflin.finder.logic
Class Graph
java.lang.Object
edu.claflin.finder.logic.Graph
- Direct Known Subclasses:
ConditionedGraph
Used to represent a graph in memory. Migrated from matrix form, the graph is
now kept track of via a list of edges and nodes. All the previous methods
remain in existence but the underlying implementation has changed.
- Version:
- 3.4 February 2, 2016
- Author:
- Charles Allen Schultz II
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe list of edges added to the graph.private final StringThe name of the Graph provided by the user.The list of the nodes added to the graph.protected booleanUsed to suppress logging.private double -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeprecated.Outdated since v3.booleanAdds an edge to the Graph.booleanDeprecated.Outdated since v3.booleanAdds a list of Edges to the graph.booleanaddNewNode(String node) Deprecated.Outdated since v3.booleanAdds a node to the graph.booleanAdds a list of nodes to the graph.booleanaddPartialGraph(List<Node> nodes, List<Edge> edges) Adds a partial graph to this graph.private voidVerifies that the node is NOT in the graph.private voidcheckNodeIndex(int nodeIndex) Deprecated.No replacement.booleancontainsNode(Node node) Checks if the graph contains the given node.copy()Copies this Graph object using the getSubGraph() method.Crosstalk of 2 subgraphs of this Graph.difference(Graph that) Difference of this Graph with a provided Graph.getAdjacencyList(Node node) Obtains an adjacency list for the supplied node based on the Graph.getEdge(int node1Index, int node2Index) Deprecated.Outdated since v3.Locates an Edge object in the edgeList and returns it.Deprecated.Outdated since v3.intGet the number of Edges in the GraphReturns the list of edges in the graph.getEdgesBack(List<Node> nodes) Gets the list edges of this Graph that involve the nodes in the given listdoubleGet the Graph's total weight (sum of all edge weights)getName()Gets the name of the graph.Gets a node based on its name.intGets the number of nodes in the graph.getNodeEdges(Node n) Get the list of Edges in which the given Node participates.intgetNodeIndex(Node node) Gets the index of a Node object in memory.intgetNodeIndex(String node) Deprecated.Outdated since v3.Returns the list of nodes in the graph.getNodeName(int nodeIndex) Deprecated.Outdated since v3.Divides the given graph into two bipartite sets.getSubGraph(int startNode, int stopNode, String nameQualifier) Deprecated.Outdated since v3.getSubGraph(ArrayList<String> subStringSet, String nameQualifier) Deprecated.Outdated since v3.getSubGraph(List<Node> nodes, String nameQualifier) Returns a subGraph of this graph.Intersects this Graph with a provided Graph.booleanDetermines whether the Graph is Bipartite.private booleanPrivate method for stepping through the adjacency lists and determining if the graph is bipartite.booleanisClique()Determines whether the Graph is a Clique.voidremoveEdge(Edge e) private voidRemove all the edges in which the given Node participates.voidremoveNode(Node node) Removes a node from the set.toString()Returns a String representation of the Graph.voidtranspose(int node1Index, int node2Index) Transposes the specified nodes.voidTransposes the specified nodes.voidDeprecated.Outdated since v3.Union this Graph with a provided Graph.Copies this Graph producing a unique copy in which there is no entanglement between the two Graph objects.uniqueCopy(String gName)
-
Field Details
-
graphName
The name of the Graph provided by the user. This value is used by the program to name output files unless specified otherwise. -
nodeList
The list of the nodes added to the graph. Used by the program to keep track of the associations within the matrix. It may be re-ordered dynamically at runtime. -
edgeList
The list of edges added to the graph. The graph is, by default, a directed graph. As such, two edges must be added to force the graph to be bidirectional. -
weight
private double weight -
suppressLog
protected boolean suppressLogUsed to suppress logging.
-
-
Constructor Details
-
Graph
Initializes the graph. Merely initializes fields. It does not set any data. Also sets the Logging Utility object. If null, the class will not log data.- Parameters:
graphName- the String which represents the name of the Graph.
-
Graph
Private constructor used by subGraph method.- Parameters:
graphName- the String which represents the name of the Graph.nodeList- the ArrayList of Node objects.edgeList- the ArrayList of Edge objects.
-
-
Method Details
-
getName
Gets the name of the graph.- Returns:
- The graph name.
-
addPartialGraph
Adds a partial graph to this graph. Specifically adds a set of nodes and a set of edges to the graph. It should be noted that nodes or edges in the graph already that attempt to be added again may cause exceptions to occur. Additionally, Nodes are added before Edges so any Edges that depend on Nodes in the add list may be safely added simultaneously. This method is the backbone structure for adding any component to the graph as all other addition methods filter through here.- Parameters:
nodes- the List<Node> containing the nodes to add.edges- the List<Edge> containing the edges to add.- Returns:
- true, always. Allows overriding in subclasses which wish to change base implementation.
-
getSubGraph
Deprecated.Outdated since v3. Replaced bygetSubGraph(java.util.List, java.lang.String)Returns a subGraph of this graph. Isolates and extracts a subgraph based on user supplied values. The new Graph is a separate Graph object.- Parameters:
startNode- the integer pointing to the start node.stopNode- the integer pointing to the stop node.nameQualifier- the String representing an additional qualifier to prepend the name of the new Graph object with.- Returns:
- the Graph object representing a subgraph of the original.
-
getSubGraph
Deprecated.Outdated since v3. Replaced bygetSubGraph(java.util.List, java.lang.String)Returns a subGraph of this graph. Isolates and extracts a subgraph based on user supplied values. The new Graph is a separate Graph object.- Parameters:
subStringSet- an ArrayList containing the String names of the desired nodes.nameQualifier- the String representing an additional qualifier to prepend the name of the new Graph object with.- Returns:
- the Graph object representing a subgraph of the original.
-
getSubGraph
Returns a subGraph of this graph. Isolates and extracts a subgraph based on a user supplied node list. The new Graph is a quasi-separate Graph. Each node utilized is directly related between the two graphs and, as such, changes to the properties of one node in the subgraph will be reflected in the super graph. To obtain an independent graph- Parameters:
nodes- the List<Node> containing the Node references.nameQualifier- the String to differentiate the Graph names.- Returns:
- the Graph representing the subgraph.
-
transpose
public void transpose(int node1Index, int node2Index) Transposes the specified nodes. Swaps the location of the nodes in memory. Specifically swaps the nodes in the nodeList as the Edge data has been uncoupled from the Node data. Newer implementation is dependent upon the int based method for performance.- Parameters:
node1Index- the integer index of the first node.node2Index- the integer index of the second node.
-
transpose
Deprecated.Outdated since v3. Replaced by {}Transposes the specified nodes. Swaps the location of the nodes in memory. This is a convenience method for transposing the nodes based on the Sting representation of the nodes.- Parameters:
node1- the String name of the first node.node2- the String name of the second node.
-
transpose
Transposes the specified nodes. Relies on the integer based method for carrying out the operation.- Parameters:
node1- the Node object in the first position.node2- the Node object in the second position.
-
getGraphWeight
public double getGraphWeight()Get the Graph's total weight (sum of all edge weights)- Returns:
- the Graph's total weight
-
copy
Copies this Graph object using the getSubGraph() method.- Returns:
- a Graph object identical to the original.
-
uniqueCopy
Copies this Graph producing a unique copy in which there is no entanglement between the two Graph objects. I.e. there are no shared nodes or edges between the two graphs. Mathematically speaking:x.getNodeList().get(0) != y.getNodeList().get(0)under any circumstances. The Nodes and Edges may remain equivalent via the equals() implementation. Further, Edge data shall remain entangled due to implementation details.- Returns:
- a unique copy of the graph object.
-
uniqueCopy
-
union
Union this Graph with a provided Graph.- Parameters:
that- the Graph to union with- Returns:
- the Graph that is the union of the two Graphs
-
intersect
Intersects this Graph with a provided Graph.- Parameters:
that- the Graph to intersect with- Returns:
- the Graph that is the intersection of the two Graphs
-
difference
Difference of this Graph with a provided Graph.- Parameters:
that- the Graph to difference with- Returns:
- the Graph that is the difference of the two Graphs
-
crosstalk
Crosstalk of 2 subgraphs of this Graph. It is the edges of the 2 subgraphs and the edges that connect the subgraphs. The subgraphs must be disjoint.- Parameters:
subgraph1- subgraph 1subgraph2- subgraph 2- Returns:
- the crosstalk or empty graph if the subgraphs are not disjoint
-
toString
Returns a String representation of the Graph. -
toStringNameless
-
getNodeCount
public int getNodeCount()Gets the number of nodes in the graph.- Returns:
- the integer representing the total number of nodes in the graph.
-
getNodeList
Returns the list of nodes in the graph.- Returns:
- the List<Node> containing the list of nodes in the graph.
-
containsNode
Checks if the graph contains the given node.- Parameters:
node- the node to check for- Returns:
- whether or not node is in this graph
-
addNewNode
Deprecated.Outdated since v3. Replaced by {}Adds a node to the graph. Adds the specified node name to the nodeList by creating and adding a new node and then calling the addNode(Node) method.- Parameters:
node- the String which denotes the name of the node to add.- Returns:
- true if the addition was successful.
-
addNode
Adds a node to the graph. Adds a Node object to the graph.- Parameters:
node- the Node object to add.- Returns:
- true if the addition was successful.
-
removeNode
Removes a node from the set. Only used with the Bron-Kerbosch algorithm right now, hopefully doesn't break anything Does NOT affect edges!!!!!!! At time of writing may cause issues if you rely on it to do so- Parameters:
node- the node to remove
-
addNodes
Adds a list of nodes to the graph.- Parameters:
nodes- the List<Node> containing the nodes to add.- Returns:
- true if the addition was successful.
-
getNodeIndex
Deprecated.Outdated since v3. Replaced by {}Gets the index of a node based on its name. Maintained with the new implementation to preserve existing uses. Will not match nodes which may have additional properties attached in future implementations.- Parameters:
node- the String representing the node to search for.- Returns:
- the index of the node or -1 if the node was not found.
-
getNodeIndex
Gets the index of a Node object in memory. Retained for older API compatibility. The ordering of the nodes is not guaranteed and may change during the program's runtime.- Parameters:
node- the Node object to search for.- Returns:
- the index of the node or -1 if the node was not found.
-
getNodeName
Deprecated.Outdated since v3. No replacement. Obtain the Node data via theNodeobject.Gets the name of the node at the specified nodeIndex. Ensures that the provided integer is within the range of available indices.- Parameters:
nodeIndex- the integer representing the index to get from the headerList.- Returns:
- the String representing the name of the node.
-
getNode
Gets a node based on its name.- Parameters:
NodeName- the String representing the node to search for.- Returns:
- the node or null if the node was not found.
-
getAdjacencyList
Obtains an adjacency list for the supplied node based on the Graph. Very inefficient, try to use the neighbors variable in the Node class instead.- Parameters:
node- the Node to obtain the adjacency list for.- Returns:
- the List of Nodes containing the adjacent Nodes.
-
checkNode
Verifies that the node is NOT in the graph. Checks to see if the provided node name is in the headerList and, hence, the dataMatrix. This is an internal method used to ensure that the algorithm is operating correctly.- Parameters:
node- the Node to check for.
-
checkNodeIndex
Deprecated.No replacement. Further operations shall utilize {)}Verifies that the nodeIndex is valid. Ensures that the node does not fall out of bounds. This is an internal method used to ensure that the algorithm is operating correctly.- Parameters:
nodeIndex- the integer of the node to check for.
-
getEdgeCount
public int getEdgeCount()Get the number of Edges in the Graph- Returns:
- the number of Edges in the Graph
-
getEdgeList
Returns the list of edges in the graph.- Returns:
- the List<Edge> containing the list of edges in the graph.
-
addEdge
Deprecated.Outdated since v3. Replaced by {}Adds an edge connecting the specified nodes in the Graph. Sets the object data for the edge dependent upon the supplied parameter.- Parameters:
node1Index- the integer value indicating the first node.node2Index- the integer value indicating the second node.edgeData- the Object that represents unique edge data (i.e. weight or edge relationship).- Returns:
- true if the addition was successful.
-
addEdge
Deprecated.Outdated since v3. Replaced by {Adds an edge connecting the specified nodes to the Graph. This is a convenience method for adding an edge using node names. Graphs are undirected so the order of the parameters does not matter.- Parameters:
node1- the String indicating the first node.node2- the String indicating the second node.edgeData- the Object that represents unique edge data (i.e. weight or edge relationship).- Returns:
- true if the addition was successful.
-
addEdge
Adds an edge to the Graph. If any edge already exists within the Graph connecting the two supplied nodes or either of the two nodes is not in the nodeList, then the edge is not added.- Parameters:
edge- the Edge object to add to the graph.- Returns:
- true if the addition was successful.
-
addEdges
Adds a list of Edges to the graph.- Parameters:
edges- the List<Edge> containing the edges to add.- Returns:
- true if the addition was successful.
-
getEdge
Deprecated.Outdated since v3. No replacement. Obtain the edge first, then obtain the data from the Edge object.Gets the value of the edge between the specified nodes.- Parameters:
node1Index- the integer value of the first node.node2Index- the integer value of the second node.- Returns:
- the Object representing the edge relationship.
-
getEdge
Deprecated.Outdated since v3. No replacement. Obtain the edge first, then obtain the data from the Edge object.Gets the value of the edge between the specified nodes. This is a convenience method for getting the edge using the node's String name.- Parameters:
node1- the String of the first node.node2- the String of the second node.- Returns:
- the Object representing the edge relationship.
-
getEdge
Locates an Edge object in the edgeList and returns it. Note that it will also return an edge with the provided source and destination parameters swapped IF AN ONLY IF said edge is undirected.- Parameters:
source- the source Node of the edge.destination- the destination Node of the edge.- Returns:
- the Edge object or null if not found.
-
getNodeEdges
Get the list of Edges in which the given Node participates.- Parameters:
n- the Node to find edges- Returns:
- the edges the node participates in
-
removeEdge
-
removeEdgesInvolving
Remove all the edges in which the given Node participates.- Parameters:
n- the participating Node
-
getEdgesBack
Gets the list edges of this Graph that involve the nodes in the given list- Parameters:
nodes- the list of nodes to found the edges from- Returns:
- the list edges of this Graph that involve the nodes in the given list
-
isClique
public boolean isClique()Determines whether the Graph is a Clique.- Returns:
- true if the Graph is a Clique
-
isBipartite
public boolean isBipartite()Determines whether the Graph is Bipartite.- Returns:
- true if the Graph is Bipartite
-
getPartiteSets
Divides the given graph into two bipartite sets.- Returns:
- two lists of nodes, each representing a bipartite set. Both lists are empty if the graph is not a valid bipartite graph.
-
isBipartite
Private method for stepping through the adjacency lists and determining if the graph is bipartite. Specifically, it uses a Depth-First model for exploring the node tree and sorting the nodes into two groups. If it successfully sorts the nodes into two groups with no invalidating edges, it returns true.- Parameters:
addSet- the current set to add a node to based on the previous.compareSet- the current set to add adjacent nodes to.current- the current Node being compared.- Returns:
- true if the structure could be bipartite.
-